#import symbol_table as symbolTable

# type size is relative to two bytes word

BOOLSIZE = 1
INTSIZE = 1
STRSIZE = 1
OBJSIZE = 1

# objects and strings are address so they are one word length

#BOOLSIZE = 2
#INTSIZE = 2


class Type(object):

	def __init__(self,name):
		self.name = name
		self.size = 0
		self.complexity = None
		self.value = None

	def getTypeName(self):
		return self.name

	def setSize(self,size):
		self.size = size
	
	def getSize(self):
		return self.size

	def getComplexity(self):
		return self.complexity

	def getValue(self):
		return self.value

	def setValue(self,value):
		self.value = value

class SimpleType(Type):

	def __init__(self,name):
		self.complexity = "simple"
		super(SimpleType,self).__init__(name)


class ComplexType(Type):

	def __init__(self,name):
		self.complexity = "complex"
		super(ComplexType,self).__init__(name)

		
#	if (paramsTypes != None):
#			self.paramTypes = paramTypes
#		else:
#			self.paramsTypes = [] # valid params types 
#
#
#	def getParamsTypes(self):
#		return self.paramsTypes
#
#	def setParamsTypes(self,paramsTypes):
#		self.paramsTypes = paramsTypes
#
#	def paramsTypesStr(self):
#		types = ""
#		for param in self.paramsTypes:
#			types += " %s"%param.getTypeName()
#		return types	


class BooleanType(SimpleType):

	def __init__(self):
		super(BooleanType,self).__init__("boolean")
		self.setSize(BOOLSIZE)	#1 word

class IntegerType(SimpleType):

	def __init__(self):
		super(IntegerType,self).__init__("int")
		self.setSize(INTSIZE)	#1 word

	@staticmethod
	def getTypeName():
		return "int"


class StringType(SimpleType):

	def __init__(self,len=None):
		super(StringType,self).__init__("string")
		#self.setSize(len)	#len bytes
		self.setSize(STRSIZE)	#

class ObjectType(ComplexType):

	def __init__(self,classname,st=None):
		super(ObjectType,self).__init__("object")
		self.st = None
		self.setSize(OBJSIZE)	#
		self.setSymbolTable(st) # st is added for cheking attributes TODO: really needed?
		self.classname = classname

	def getClassName(self):
		return self.classname

	def setClassName(self,classname):
		self.classname = classname

	def getSymbolTable(self):
		return self.st

	def setSymbolTable(self,st):
		self.st = st

	def getObjectSize(self):
		return self.st.getObjectSize()

class FunctionType(ComplexType):

	def __init__(self,paramsTypes=None,returnType=None):
		super(FunctionType,self).__init__("function")

		if (returnType != None):
			self.returnType = IntegerType()
		else:
		 	self.returnType = None


		
	
	def getReturnType(self):
		return self.returnType

	def addReturnType(self):
		self.returnType = IntegerType()

	
